rm(list = ls())
require(stats4)
require(nlWaldTest)
require("multiwayvcov")
require(msm)

data21=read.csv("C:/Users/naten/OneDrive - University of Tennessee/Dean Stuff/data/columbia_experiment_december6noon_type7clean.csv", header=TRUE)
data22=read.csv("C:/Users/naten/OneDrive - University of Tennessee/Dean Stuff/data/columbia_experiment_december15_type7clean.csv", header=TRUE)
data23=read.csv("C:/Users/naten/OneDrive - University of Tennessee/Dean Stuff/data/columbia_experiment_january26_type7(clean).csv", header=TRUE)


dataframe21=data.frame(data21)
dataframe22=data.frame(data22)
dataframe23=data.frame(data23)

#some definitions
expframe=rbind(dataframe21,dataframe22,dataframe23)
expframe=subset(expframe,uid>800)
expframe$correct <-(expframe$state==4&(expframe$response==2|expframe$response==7|expframe$response==8|expframe$response==9))|(expframe$state==3&(expframe$response==1|expframe$response==6|expframe$response==3|expframe$response==5))
expframe$incentive <- (expframe$qid==5)*5+(expframe$qid==1)*40+(expframe$qid==6)*70+(expframe$qid==7)*95
accuracy=c(sum((expframe$incentive==5)*expframe$correct)/sum(expframe$incentive==5),sum((expframe$incentive==40)*expframe$correct)/sum(expframe$incentive==40),sum((expframe$incentive==70)*expframe$correct)/sum(expframe$incentive==70),sum((expframe$incentive==95)*expframe$correct)/sum(expframe$incentive==95))
incentivec=c(5,40,70,95)
uidlist=unique(expframe$uid)

#check N
#**
length(uidlist)
#**


#Graph performance in low incentive against performance in high incentive (fixed and marginal costs)
accuracylowinc=vector('numeric')
accuracyhighinc=vector('numeric')
for(i in 1:length(uidlist)){
playframelow=subset(expframe,uid==uidlist[i]& incentive==incentivec[1])
playframehigh=subset(expframe,uid==uidlist[i]& incentive==incentivec[4])
accuracylowinc[i]=sum(playframelow$correct)/length(playframelow$correct)
accuracyhighinc[i]=sum(playframehigh$correct)/length(playframehigh$correct)
}

#***********************************
plot(accuracylowinc,accuracyhighinc, xlab="Accuracy 5% Incentive",ylab="Accuracy 95% Incentive",xlim=c(0,1), ylim=c(0,1))
lines(1:100/100,1:100/100)
#**********************************
